package com.kukudexin;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * @author: 酷酷的鑫
 * @Date: 2021/12/8 16:50
 * @description:
 */
public class Test13 {
    public static void main(String[] args) {
        Collection<String> strCollection = new ArrayList<>();
        Collections.addAll(strCollection, "xx", "oo", "dd", "mm", "jj");
        Collection<String> anotherCollection = new ArrayList<>();
        CopyCollection1(strCollection, anotherCollection);

        Collection<Object> destCollection = new ArrayList<>();
        CopyCollection(strCollection,destCollection);
        System.out.println(destCollection);
    }
    //定义方法, 把一个Collection集合中的数据添加到另外一个Collection集合中, 需要通过参数来接收两个Collection集合,
    public static <T> void CopyCollection(Collection<? extends T> from , Collection<T> to){
        for (T t : from) {
            to.add(t);
        }
    }

    //定义方法, 把一个Collection集合中的数据添加到另外一个Collection集合中, 需要通过参数来接收两个Collection集合, 还要求这两个集合中存储元素的类型是一样的, 但是存储什么类型的数据不确定, 可以定义泛型方法
    public static <T> void CopyCollection1(Collection<T> from , Collection<T> to){
        for (T t : from) {
            to.add(t);
        }
    }
}
